var columnWidth = 260;
var gutterWidth = 46;
if(isMobile){
	var proportion = $(window).width()/375;
	columnWidth = Math.floor(154*proportion);
	gutterWidth = Math.floor(19*proportion);
}
 function item_masonry(){ 
	$('.img-detail img').load(function(){ 
		$('.infinite-scroll').masonry({ 
			itemSelector: '.item',
			columnWidth:columnWidth,
			gutterWidth:gutterWidth								
		});	
		//瀑布流
		$("img.lazy").lazyload({ 
	        placeholder : "./images/images_4@2x.png",
	        effect: "show",
	        threshold :600
	    });	
	});
	//瀑布流
	$("img.lazy").lazyload({ 
        placeholder : "./images/images_4@2x.png",
        effect: "show",
        threshold :600
    });	
	$('.infinite-scroll').masonry({ 
		itemSelector: '.item',
		columnWidth:columnWidth,
		gutterWidth:gutterWidth								
	});	
}
item_masonry();
$(".infinite-scroll").infinitescroll({
	navSelector: ".recommend-more",
	nextSelector: ".recommend-more a",
	itemSelector: ".item",
	requestUrl: "./lib/recommend.json?type=home&categor_id=1&page=",
	
	loading:{
		img: "images/masonry_loading_1.gif",
		msgText: ' ',
		finishedMsg: '',
		render: function(resData,opts){
			var data = "";
			try{
                var temp = JSON.parse(resData);
                if(temp.code == 200) {
                    if(opts.state.currPage >= temp.data.last_page){
                        opts.state.isFinished = true;
                    }
                    $.each(temp.data.data,function(i,item){
                        data += '<div class="item"><a class="img-show" href="'+item.href1+'"><img class="lazy" data-original="'+item.cover+'"></a><a class="descrption" href="'+item.href2+'">'+item.name+'</a><div class="tips"><a href="'+item.href5+'">#'+item.category_name+'</a>';
                            if(item.brand_list && item.brand_list.length>0){
                                $.each(item.brand_list,function(j,it){
                                    data += '<a data-id='+it.brand_id+' href="'+item.href3+'">#'+it.brand_name+'</a>';
                                })
                            }
                        data += '</div></div>';  
                    })
                }
            }catch(e){}
            return data;
		},
		finished: function(opts){
			if(opts.state.isFinished){ //结束事件
				$(".recommend-more").remove();
				$("#infscr-loading").hide();
				$(window).unbind('.infscr');
			}
		}	
	},errorCallback:function(res){ 
		console.log(res);
	}
	
},function(newElements){
	var $newElems = $(newElements);
	$('.infinite-scroll').masonry('appended', $newElems, false);
	$newElems.fadeIn();
	item_masonry();
	return;
});